package com.taijihuabao.common.activititasklistener.raisetasklistener;

import com.taijihuabao.modules.entity.RaiseSalaryEntity;
import com.taijihuabao.modules.mapper.RaiseSalaryMapper;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

@Component
public class RaiseSalaryListener implements TaskListener {
    @Resource
    private RaiseSalaryMapper raiseSalaryMapper;
    @Override
    public void notify(DelegateTask delegateTask) {
        //审批id
        String businessKey = delegateTask.getExecution().getProcessInstanceBusinessKey();
        //查询审批单
        RaiseSalaryEntity raiseSalaryEntity = raiseSalaryMapper.selectById(Long.valueOf(businessKey));
        if(!Objects.isNull(raiseSalaryEntity)){
            //设置申请人（修改提交申请）
            delegateTask.setAssignee(String.valueOf(raiseSalaryEntity.getRaiseUserId()));
        }
    }
}
